<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%> 
<html>
<head>  
  <script type="text/javascript">
  var grid;
  $(document).ready(function() {	
	  $.ajax({
		  type: 'POST',
		  url: "../channelinf/getChannelByTp.do?chn_tp=1",				  
		  success: function(data) {	
			  var msg = [];			  
			  for(var i=0;i<data.length;i++){
				  if(i==0){
					  msg.push({ "id": data[i].ID, "text": data[i].TEXT,"selected":true });  
				  }else{					  
				  	  msg.push({ "id": data[i].ID, "text": data[i].TEXT });				  
				  }
			  }			 
			  $("#channel_no").combobox({
				   	data:msg,
				    valueField:'id',
				    textField:'text',
				    panelHeight:'auto',
				    editable:false ,
				    onLoadSuccess:function(param){
				    	$(".easyui-datebox").datebox('setValue', "${currentDate}");
				    	var channel_no="";
				    	if(param.length>0){
				    		channel_no=param[0].id;			    		
				    	}
				    	grid = $("#hosttermTableId").jpgrid({
							url: "getHostTermListJson.do",
							queryParams: {
								channel_no: channel_no
							}, 
							columns: [
								{title: "商户号", field: "MCHNT_CD"},
								{title: "终端号", field: "TERM_ID"},
								{title: "渠道方商户号", field: "TRF_MCHNT_CD"},
								{title: "渠道方终端号", field: "TRF_TERM_ID"},
								{title: "商户名称", field: "TERM_NM"},
								{title: "所属机构", field: "INSNAME"},
								{title: "业务名称", field: "SERNAME"},
								{title: "业务参数名称", field: "PURNAME"},
								{title: "所属地区", field: "AREANAME"},
								{title: "收单行号", field: "ACQ_INS_CD"},
								{title: "主秘钥索引", field: "MASTER_KEY_IDX"},
								{title: "主秘钥", field: "MASTER_KEY"},
								{title: "所属通道", field: "CHANNEL"},
								{title: "借记卡-最小手续费(元)", field: "DEBIT_MINFEE"},
								{title: "借记卡-扣率(‱)", field: "DEBIT_RATE"},
								{title: "借记卡-最大手续费(元)", field: "DEBIT_MAXFEE"},
								{title: "贷记卡-最小手续费(元)", field: "CREDIT_MINFEE"},
								{title: "贷记卡-扣率(‱)", field: "CREDIT_RATE"},
								{title: "贷记卡-最大手续费(元)", field: "CREDIT_MAXFEE"},
								{title: "签到标志", field: "SIGN_ST"}								
							]
						});	
				    }
				}); 			  
	      }
	  });	 
	  $("#importHostTerm").click(function(){		  
		  var channel_no=$("#channel_no").val();
		  if(channel_no==null||channel_no==""||channel_no==undefined){
			  $.jpmessage.info('请选择所属通道！');
			  return;
		  } 
		  var file=$("#insertFile").textbox("getValue");
		  var file_typename = file.substring(file.lastIndexOf('.'), file.length);		  
		  if(file==null||file==""||file==undefined||file_typename!=".xls"){
			  $.jpmessage.info('请选择excel(.xls)文件！');
			  return;
		  }
		  
			var form = new FormData(document.getElementById("importFileForm"));
			form.append("channel_no",$("#channel_no").val());
			$.ajax({
	               url:"../hostterm/importHostTerm.do",
	               type:"post",
	               data:form,
	               processData:false,
	               contentType:false,
	               success:function(data){
	               	if("success"==data){
	               		  $.jpmessage.info('导入成功！');
	               		}else if("chnno"==data){
	               		  $.jpmessage.info('请选择所属通道！');
	               		}else if("file"==data){
	               		  $.jpmessage.info('请选择excel(.xls)文件！');
	               		}else{
	               		  $.jpmessage.info('行号['+data+']导入失败！');
	               		}	
	               }
			}); 
			
	  });
	  
	  $("#closeImport").click(function(){		  
		  $("#insertFile").textbox("setValue", "");	
		    $('#import-excel-template').window('close');
	  });
	  
	  $("#updateHostTerm").click(function(){			  
		  var channel_no=$("#channel_no").val();
		  if(channel_no==null||channel_no==""||channel_no==undefined){
			  $.jpmessage.info('请选择所属通道！');
			  return;
		  } 
		  var file=$("#updateFile").textbox("getValue");	
		  var file_typename = file.substring(file.lastIndexOf('.'), file.length);		  
		  if(file==null||file==""||file==undefined||file_typename!=".xls"){
			  $.jpmessage.info('请选择excel(.xls)文件！');
			  return;
		  }
		  
			var form = new FormData(document.getElementById("updateFileForm"));
			form.append("channel_no",$("#channel_no").val());
			$.ajax({
                url:"../hostterm/updateHostTerm.do",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                success:function(data){
                	if("success"==data){
                		  $.jpmessage.info('批量修改成功！');
                		}else if("chnno"==data){
                		  $.jpmessage.info('请选择所属通道！');
                		}else if("file"==data){
                		  $.jpmessage.info('请选择excel(.xls)文件！');
                		}else{
                		  $.jpmessage.info('行号['+data+']批量修改失败！');
                		}	
                }
			});
	  });
	  
	  $("#closeUpdate").click(function(){		  
		  $("#updateFile").textbox("setValue", "");	
		  $('#update-excel-template').window('close');
	  });
  });
  function doSearch() {	 
	  grid.load({
			channel_no: $('#channel_no').val(),
			mchnt_cd: $('#mchnt_cd').val(),
			trf_mchnt_cd: $('#trf_mchnt_cd').val(),
			term_nm: $('#term_nm').val(),
			ins_cd: $('#ins_cd').val(),
			ins_cn_nm: $('#ins_cn_nm').val(),
			sign_st: $('#sign_st').val(),
			rec_crt_ts_start: $('#rec_crt_ts_start').val(),
			rec_crt_ts_end: $('#rec_crt_ts_end').val()
		});
}

function addHostTerm(url){	  
	  commonDetail(url+$('#channel_no').val(),"save","hosttermTableId");
}
function modifyHostTerm(url){	  
	  commonDetail(url+$('#channel_no').val()+"&host_term_uuid=","update","hosttermTableId");
}
function deleteHostTerm(url){	  
	  commonDel(url+$('#channel_no').val()+"&host_term_uuids=","delete","hosttermTableId");
}
function importHostTerm(url){
	$("#insertFile").textbox("setValue", "");	
	$('#import-excel-template').window('open');
	document.getElementById("importFileForm").style.display = "block";
}
function updateHostTerm(url){
	$("#updateFile").textbox("setValue", "");	
	$('#update-excel-template').window('open');
	document.getElementById("updateFileForm").style.display = "block";
}
function exportTemplate(){
	commonFileDownload("../hostterm/exportTemplate.do", "importFileForm");
}

function batchModifyRate(url){
	var commonTree;
	commonTree = showInsTree(insselected, null,null);
	function insselected(){
		var channel_no=$("#channel_no").val();
		  if(channel_no==null||channel_no==""||channel_no==undefined){
			  $.jpmessage.info('请选择所属通道！');
			  return;
		  } 		  
		var nodes = commonTree.getSelectedNodes();
		if(nodes && nodes.length > 0){
			var name=nodes[0].NAME;
			var ins_cd=name.substring(0, name.indexOf('-'));				
			var form = new FormData();
			form.append("channel_no",$("#channel_no").val());
			form.append("ins_cd",ins_cd);
		  	$.ajax({
	          url:url,
	          type:"post",
	          data:form,
	          processData:false,
	          contentType:false,
	          success:function(data){
	          	if("success"==data){
	          		  $.jpmessage.info('批量设置扣率成功,请稍后刷新查看！');
	          		}else{
	          		  $.jpmessage.info('批量设置扣率失败！');
	          		}	
	          }
			});
		}else{
			$.jpmessage.info('请选择机构！');			
		} 
	}
}
function modifyAccountToChannel(url){
	  var channel_no=$("#channel_no").val();
	  if(channel_no==null||channel_no==""||channel_no==undefined){
		  $.jpmessage.info('请选择所属通道！');
		  return;
	  }
	
	  var ids = "";					
		var checkedItems = checkSelected("hosttermTableId", true);
		if(!checkedItems){
			return;
		}
		ids = (checkedItems[0]).UUID;	
		var form = new FormData();
		form.append("channel_no",$("#channel_no").val());
		form.append("host_term_uuid",ids);
	 	
 		$.ajax({
	          url:url,
	          type:"post",
	          data:form,
	          processData:false,
	          contentType:false,
	          success:function(data){
	          	if("success"==data){
	          		  $.jpmessage.info('修改结算信息成功,请稍后刷新查看！');
	          		}else{
	          		  $.jpmessage.info('修改结算信息失败！');
	          		}	
	          }
			});  
}
  </script>
</head>
<body class="easyui-layout list_body"  >
	<form id="hosttermForm" name="hosttermForm" method="post" enctype="multipart/form-data">
		<div class="list_body_north" data-options="region:'north'"  border="false" >
			<!-- 查询表单 -->
			<div  class="datagrid-toolbar" border="false"  >
				<div style="padding:3px">
				<span>所属通道:</span>
				<input class="easyui-combobox" id="channel_no" name="channel_no" >
				<span>创建开始日期:</span>
				<input  id="rec_crt_ts_start" name="rec_crt_ts_start" class="easyui-datebox" data-options="editable:false" value="${currentDate}"/>
				<span>创建结束日期:</span>
				<input  id="rec_crt_ts_end" name="rec_crt_ts_end" class="easyui-datebox" data-options="editable:false" value="${currentDate}"/>
				<span>商户号:</span>
				<input id="mchnt_cd" type="text" name="mchnt_cd" class="easyui-textbox"  >	
				</div>
				<div style="padding:3px">
				<span>商户名称:</span>
				<input id="term_nm" type="text" name="term_nm" class="easyui-textbox"  >	
				<span>机构号:</span>
				<input id="ins_cd" type="text" name="ins_cd" class="easyui-textbox"  >
				<span>机构名称:</span>
				<input id="ins_cn_nm" type="text" name="ins_cn_nm" class="easyui-textbox"  >
				<span>渠道方商户号:</span>
				<input id="trf_mchnt_cd" type="text" name="trf_mchnt_cd" class="easyui-textbox"  >	
				</div>
				<div style="padding:3px">										
				<span>签到标志:</span>			
				<code:codeSelect id="sign_st" name="sign_st" code_type="sign_st" showSelect="true" ></code:codeSelect>							
			 	<a href="#" class="easyui-linkbutton btn" iconCls="icon-search" onclick="doSearch() ">查询</a>
			 	<a href="#" class="easyui-linkbutton btn" iconCls="icon-reload" onclick="resetForm() ">重置</a>
				</div>			
			</div>
			<!-- 自定义标签工具栏 -->
			<jiepos:buttonOperateTag menuCode="${menuCode}"></jiepos:buttonOperateTag>	
		</div>
		<div data-options="region:'center'" border="false"  class="list_body_center">		
			<!-- 表格 -->
			<table id="hosttermTableId" fit="true"></table>
		</div>
	</form>

<div class="easyui-window" id="import-excel-template" title="文件上传" style="width:400px;height:160px;padding:2px;" closed="true">
    <form id="importFileForm" method="post" enctype="multipart/form-data" style="display:none">
        <table style="margin:5px;height:70px;">
            <tr>
                <td>请选择文件</td>
                <td width="5px;"></td>
                <td>
                <!-- <input type="file" class="easyui-filebox" id="fileImport" name="fileImport" style="width:260px;"> -->
                <input class="easyui-filebox" id="insertFile" name="insertFile" buttonText="选择" data-options="prompt:'选择文件'" style="width:260px"> 
                </td>
                <td></td></tr>
            <tr>
            	<td><a class="easyui-linkbutton" onclick="exportTemplate()" data-options="iconCls:'icon-print'" data-bind="" href="javascript:void(0)">模板下载</a></td>
            </tr>
        </table><div style="text-align:center;clear:both;margin:5px;">
            <a id="importHostTerm" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" data-bind="" href="javascript:void(0)">上传</a>
            <a id="closeImport" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" data-bind="" href="javascript:void(0)">关闭</a>
        </div>
    </form>
</div>
<div class="easyui-window" id="update-excel-template" title="文件上传" style="width:400px;height:160px;padding:2px;" closed="true">
    <form id="updateFileForm" method="post" enctype="multipart/form-data" style="display:none">
        <table style="margin:5px;height:70px;">
            <tr>
                <td>请选择文件</td>
                <td width="5px;"></td>
                <td>
                <!-- <input type="file" class="easyui-filebox" id="updateFile" name="updateFile" style="width:260px;"> -->
                <input class="easyui-filebox" id="updateFile" name="updateFile" buttonText="选择" data-options="prompt:'选择文件'" style="width:260px"> 
                </td>
                <td></td></tr>
            <tr>
            	<td><a class="easyui-linkbutton" onclick="exportTemplate()" data-options="iconCls:'icon-print'" data-bind="" href="javascript:void(0)">模板下载</a></td>
            </tr>
        </table><div style="text-align:center;clear:both;margin:5px;">
            <a id="updateHostTerm" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" data-bind="" href="javascript:void(0)">上传</a>
            <a id="closeUpdate" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" data-bind="" href="javascript:void(0)">关闭</a>
        </div>
    </form>
</div>
</body>
 </html>